package com.datang.pet.api.talkController;/*
 * @auther 顶风少年
 * @mail dfsn19970313@foxmail.com
 * @date 2019-06-14 10:29
 * @notify
 * @version 1.0
 */

import com.datang.pet.common.response.Result;
import com.datang.pet.common.utils.MD5;
import com.datang.pet.common.utils.StringUtils;
import com.datang.pet.service.TalkService;
import com.datang.pet.vo.LikeTalkRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LikeTalkController {

    @Autowired
    private TalkService talkService;

    @PostMapping("likeTalk")
    public Result likeTalk(@RequestBody LikeTalkRequest likeTalkRequest) throws Exception {
        String userId = likeTalkRequest.getUserId();

        String talkId = likeTalkRequest.getTalkId();

        String type = likeTalkRequest.getType();

        String talkUserId = likeTalkRequest.getTalkUserId();


        if (!StringUtils.isNUll(talkId)) {
            throw new Exception("喵文id不能为空");
        }
        if (!StringUtils.isNUll(userId)) {
            throw new Exception("用户id不能为空");
        }
        if (!StringUtils.isNUll(type)) {
            throw new Exception("类型不能为空");
        }

        if (!StringUtils.isNUll(talkUserId)) {
            throw new Exception("发布用户不能为空");
        }

        //md5解密userId(普通用户)
        try {
            userId = (MD5.decryptData(userId));
        } catch (Exception e) {
            throw new Exception("userId解密出错！");
        }


        talkService.likeTalk(userId, talkId, type, talkUserId);
        return Result.ok("成功");
    }
}
